#! /usr/bin/env node

const inquirer = require('inquirer')
const path = require('path')
const fs = require('fs')
const ejs = require('ejs')


console.log('my-node-cli working ~')
// yarn link 可能会无效，可以使用 npm link 

inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'Your name',
    default: 'my-node-cli'
  }
]).then(answers => {
  const destUrl = path.join(__dirname, 'templates'); 
  const cwdUrl = process.cwd();
  fs.readdir(destUrl, (err, files) => {
    if (err) throw err;
    files.forEach((file) => {
      ejs.renderFile(path.join(destUrl, file), answers).then(data => {
        fs.writeFileSync(path.join(cwdUrl, file) , data)
      })
    })
  })
})

